package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.project.system.domain.HappyCatUser;
import com.happy.cat.project.system.service.IHappyCatUserService;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 用户;储存用户信息Controller
 *
 * @author verne
 * @date 2020-08-04
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/happyCatUser" )
@Api("用户;储存用户信息 API")
public class HappyCatUserController extends BaseController {

    private final IHappyCatUserService iHappyCatUserService;

    /**
     * 查询用户;储存用户信息列表
     */
    @ApiOperation(value = "查询用户;储存用户信息列表",notes = "查询用户;储存用户信息列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:happyCatUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(HappyCatUser happyCatUser)
    {
        startPage();
        LambdaQueryWrapper<HappyCatUser> lqw = new LambdaQueryWrapper<HappyCatUser>();
        if (StringUtils.isNotBlank(happyCatUser.getRealName())){
            lqw.like(HappyCatUser::getRealName ,happyCatUser.getRealName());
        }
        if (StringUtils.isNotBlank(happyCatUser.getPhone())){
            lqw.eq(HappyCatUser::getPhone ,happyCatUser.getPhone());
        }
        if (happyCatUser.getBirthDate() != null){
            lqw.eq(HappyCatUser::getBirthDate ,happyCatUser.getBirthDate());
        }
        if (happyCatUser.getAge() != null){
            lqw.eq(HappyCatUser::getAge ,happyCatUser.getAge());
        }
        if (happyCatUser.getStatus() != null){
            lqw.eq(HappyCatUser::getStatus ,happyCatUser.getStatus());
        }
        List<HappyCatUser> list = iHappyCatUserService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出用户;储存用户信息列表
     */
    @ApiOperation(value = "导出用户;储存用户信息列表",notes = "导出用户;储存用户信息列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:happyCatUser:export')" )
    @Log(title = "用户;储存用户信息" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(HappyCatUser happyCatUser) {
        LambdaQueryWrapper<HappyCatUser> lqw = new LambdaQueryWrapper<HappyCatUser>(happyCatUser);
        List<HappyCatUser> list = iHappyCatUserService.list(lqw);
        ExcelUtil<HappyCatUser> util = new ExcelUtil<HappyCatUser>(HappyCatUser. class);
        return util.exportExcel(list, "happyCatUser" );
    }

    /**
     * 获取用户;储存用户信息详细信息
     */
    @ApiOperation(value = "获取用户;储存用户信息详细信息",notes = "获取用户;储存用户信息详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:happyCatUser:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iHappyCatUserService.getById(id));
    }

    /**
     * 新增用户;储存用户信息
     */
    @ApiOperation(value = "新增用户;储存用户信息",notes = "新增用户;储存用户信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:happyCatUser:add')" )
    @Log(title = "用户;储存用户信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HappyCatUser happyCatUser) {
        return toAjax(iHappyCatUserService.save(happyCatUser) ? 1 : 0);
    }

    /**
     * 修改用户;储存用户信息
     */
    @ApiOperation(value = "修改用户;储存用户信息",notes = "修改用户;储存用户信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:happyCatUser:edit')" )
    @Log(title = "用户;储存用户信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HappyCatUser happyCatUser) {
        return toAjax(iHappyCatUserService.updateById(happyCatUser) ? 1 : 0);
    }

    /**
     * 删除用户;储存用户信息
     */
    @ApiOperation(value = "删除用户;储存用户信息",notes = "删除用户;储存用户信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:happyCatUser:remove')" )
    @Log(title = "用户;储存用户信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iHappyCatUserService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
